package com.watercube.note.biz.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.watercube.field.cache.CacheField.ClientCacheField;
import com.watercube.note.biz.user.dao.ClientDao;
import com.watercube.note.biz.user.entity.Client;
import com.watercube.note.biz.user.entity.ClientExample;
import com.watercube.note.biz.user.service.ClientService;
import com.watercube.service.base.impl.BaseServiceImpl;

@Service
public class ClientServiceImpl extends BaseServiceImpl<Client, String, ClientExample> implements ClientService {

	private ClientDao clientDao;

	public ClientDao getClientDao() {
		return clientDao;
	}

	@Autowired
	public void setClientDao(ClientDao clientDao) {
		this.clientDao = clientDao;
		super.setBaseDao(clientDao);
	}

	@Override
	@Cacheable(value = ClientCacheField.CLIENT_KEYS, key = "'" + ClientCacheField.CLIENT + "'+#p0")
	public String getClientCacheById(String clientId) {
		System.err.println("run into db");
		Client selectByPrimaryKey = clientDao.selectByPrimaryKey(clientId);
		return JSONObject.toJSONString(selectByPrimaryKey);
	}

	@Override
	@CacheEvict(value = ClientCacheField.CLIENT_KEYS, key = "'" + ClientCacheField.CLIENT + "'+#p0")
	public void deleteClientCache(String clientId) {
	}

}
